package geppetto.phraseHMM.phraseExtraction.extractedphrase.data;

import geppetto.phraseHMM.phraseExtraction.extractedphrase.ExtractedPhrasePairData;

import java.util.ArrayList;
import java.util.HashMap;

public class ExtractedSentenceData extends ExtractedPhrasePairData{

	int sentenceNumber;
	double count = 1;
	
	public ExtractedSentenceData(int sentenceNumber, double count) {
		super();
		this.sentenceNumber = sentenceNumber;
		this.count = count;
	}	

	public int getSentenceNumber() {
		return sentenceNumber;
	}

	public void setSentenceNumber(int sentenceNumber) {
		this.sentenceNumber = sentenceNumber;
	}

	public double getCount() {
		return count;
	}

	public void setCount(double count) {
		this.count = count;
	}

	@Override
	public void merge(ArrayList<HashMap<String, ExtractedPhrasePairData>> generalData, ArrayList<ExtractedPhrasePairData> data) {
		ArrayList<Integer> sentenceNumbers = new ArrayList<Integer>();
		double count = 0;
		for(ExtractedPhrasePairData d : data){
			if(d instanceof ExtractedSentenceData){
				ExtractedSentenceData extSenData = ((ExtractedSentenceData)d);
				if(!sentenceNumbers.contains(extSenData.getSentenceNumber())){
					sentenceNumbers.add(extSenData.getSentenceNumber());
					count += extSenData.getCount();
				}
			}
			else{
				System.err.println("trying to merge an instance of ScoreData to with another type of class");
				System.exit(-1);
			}
		}
		this.count = count;
	}

	@Override
	public String toString() {
		return String.valueOf(getSentenceNumber()+":"+getCount());
	}
	
	public static ExtractedSentenceData parseString(String s) {
		String[] args = s.split(":");
		return new ExtractedSentenceData(Integer.parseInt(args[0]),Double.parseDouble(args[1]));
	}

}
